home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / frogger.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  316 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. static int flipscreen;
  14.  
  15. unsigned char *frogger_attributesram;
  16.  
  17. /* Cocktail mode implemented by Chad Hendrickson, July 26, 1999           */
  18.  
  19. /***************************************************************************
  20.  
  21.   Convert the color PROMs into a more useable format.
  22.  
  23.   Frogger has one 32 bytes palette PROM, connected to the RGB output
  24.   this way:
  25.  
  26.   bit 7 -- 220 ohm resistor  -- BLUE
  27.         -- 470 ohm resistor  -- BLUE
  28.         -- 220 ohm resistor  -- GREEN
  29.         -- 470 ohm resistor  -- GREEN
  30.         -- 1  kohm resistor  -- GREEN
  31.         -- 220 ohm resistor  -- RED
  32.         -- 470 ohm resistor  -- RED
  33.   bit 0 -- 1  kohm resistor  -- RED
  34.  
  35.   Additionally, there is a bit which is 1 in the upper half of the display
  36.   (136 lines? I'm not sure of the exact value); it is connected to blue
  37.   through a 470 ohm resistor. It is used to make the river blue instead of
  38.   black.
  39.  
  40. ***************************************************************************/
  41. void frogger_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  42. {
  43.     int i;
  44.  
  45.  
  46.     for (i = 0;i < 32;i++)
  47.     {
  48.         int bit0,bit1,bit2;
  49.  
  50.  
  51.         bit0 = (color_prom[i] >> 0) & 0x01;
  52.         bit1 = (color_prom[i] >> 1) & 0x01;
  53.         bit2 = (color_prom[i] >> 2) & 0x01;
  54.         palette[3*i] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  55.         bit0 = (color_prom[i] >> 3) & 0x01;
  56.         bit1 = (color_prom[i] >> 4) & 0x01;
  57.         bit2 = (color_prom[i] >> 5) & 0x01;
  58.         palette[3*i + 1] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.         bit0 = 0;
  60.         bit1 = (color_prom[i] >> 6) & 0x01;
  61.         bit2 = (color_prom[i] >> 7) & 0x01;
  62.         palette[3*i + 2] = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  63.     }
  64.  
  65.     /* use an otherwise unused pen for the river background */
  66.     palette[3*4] = 0;
  67.     palette[3*4 + 1] = 0;
  68.     palette[3*4 + 2] = 0x47;
  69.  
  70.     /* normal */
  71.     for (i = 0;i < 4 * 8;i++)
  72.     {
  73.         if (i & 3) colortable[i] = i;
  74.         else colortable[i] = 0;
  75.     }
  76.     /* blue background (river) */
  77.     for (i = 4 * 8;i < 4 * 16;i++)
  78.     {
  79.         if (i & 3) colortable[i] = i - 4*8;
  80.         else colortable[i] = 4;
  81.     }
  82. }
  83.  
  84.  
  85.  
  86. WRITE_HANDLER( frogger_attributes_w )
  87. {
  88.     if ((offset & 1) && frogger_attributesram[offset] != data)
  89.     {
  90.         int i;
  91.  
  92.  
  93.         for (i = offset / 2;i < videoram_size;i += 32)
  94.             dirtybuffer[i] = 1;
  95.     }
  96.  
  97.     frogger_attributesram[offset] = data;
  98. }
  99.  
  100. WRITE_HANDLER( frogger_flipscreen_w )
  101. {
  102.     if (flipscreen != (data & 1))
  103.     {
  104.         flipscreen = data & 1;
  105.         memset(dirtybuffer,1,videoram_size);
  106.     }
  107. }
  108.  
  109.  
  110. /***************************************************************************
  111.  
  112.   Draw the game screen in the given osd_bitmap.
  113.   Do NOT call osd_update_display() from this function, it will be called by
  114.   the main emulation engine.
  115.  
  116. ***************************************************************************/
  117. void frogger_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  118. {
  119.     int i,offs;
  120.  
  121.     /* for every character in the Video RAM, check if it has been modified */
  122.     /* since last time and update it accordingly. */
  123.     for (offs = videoram_size - 1;offs >= 0;offs--)
  124.     {
  125.         if (dirtybuffer[offs])
  126.         {
  127.             int sx,sy,col;
  128.  
  129.  
  130.             dirtybuffer[offs] = 0;
  131.  
  132.             sx = offs % 32;
  133.             sy = offs / 32;
  134.             col = frogger_attributesram[2 * sx + 1] & 7;
  135.             col = ((col >> 1) & 0x03) | ((col << 2) & 0x04);
  136.  
  137.             if (flipscreen)
  138.             {
  139.                 sx = 31 - sx;
  140.                 sy = 31 - sy;
  141.                 drawgfx(tmpbitmap,Machine->gfx[0],
  142.                         videoram[offs],
  143.                         col + (sx >= 16 ? 8 : 0),    /* blue background in the lower 128 lines */
  144.                         flipscreen,flipscreen,8*sx,8*sy,
  145.                         0,TRANSPARENCY_NONE,0);
  146.             }
  147.             else
  148.             {
  149.                 drawgfx(tmpbitmap,Machine->gfx[0],
  150.                         videoram[offs],
  151.                         col + (sx <= 15 ? 8 : 0),    /* blue background in the upper 128 lines */
  152.                         flipscreen,flipscreen,8*sx,8*sy,
  153.                         0,TRANSPARENCY_NONE,0);
  154.             }
  155.         }
  156.     }
  157.  
  158.  
  159.     /* copy the temporary bitmap to the screen */
  160.     {
  161.         int scroll[32],s;
  162.  
  163.         for (i = 0;i < 32;i++)
  164.         {
  165.             s = frogger_attributesram[2 * i];
  166.             if (flipscreen)
  167.             {
  168.                 scroll[31-i] = (((s << 4) & 0xf0) | ((s >> 4) & 0x0f));
  169.             }
  170.             else
  171.             {
  172.                 scroll[i] = -(((s << 4) & 0xf0) | ((s >> 4) & 0x0f));
  173.             }
  174.         }
  175.  
  176.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  177.     }
  178.  
  179.  
  180.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  181.     /* order, to have the correct priorities. */
  182.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  183.     {
  184.         if (spriteram[offs + 3] != 0)
  185.         {
  186.             int x,y,col;
  187.  
  188.             x = spriteram[offs + 3];
  189.             y = spriteram[offs];
  190.             y = ((y << 4) & 0xf0) | ((y >> 4) & 0x0f);
  191.             col = spriteram[offs + 2] & 7;
  192.             col = ((col >> 1) & 0x03) | ((col << 2) & 0x04);
  193.  
  194.             if (flipscreen)
  195.             {
  196.                 x = 242 - x;
  197.                 y = 240 - y;
  198.                 drawgfx(bitmap,Machine->gfx[1],
  199.                         spriteram[offs + 1] & 0x3f,
  200.                         col,
  201.                         !(spriteram[offs + 1] & 0x40),!(spriteram[offs + 1] & 0x80),
  202.                         x,30*8 - y,
  203.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  204.             }
  205.             else
  206.             {
  207.                 drawgfx(bitmap,Machine->gfx[1],
  208.                         spriteram[offs + 1] & 0x3f,
  209.                         col,
  210.                         spriteram[offs + 1] & 0x40,spriteram[offs + 1] & 0x80,
  211.                         x,30*8 - y,
  212.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  213.             }
  214.         }
  215.     }
  216. }
  217.  
  218.  
  219. /* the alternate version doesn't have the sprite & scroll registers mangling, */
  220. /* but it still has the color code mangling. */
  221. void frogger2_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  222. {
  223.     int i,offs;
  224.  
  225.     /* for every character in the Video RAM, check if it has been modified */
  226.     /* since last time and update it accordingly. */
  227.     for (offs = videoram_size - 1;offs >= 0;offs--)
  228.     {
  229.         if (dirtybuffer[offs])
  230.         {
  231.             int sx,sy,col;
  232.  
  233.             dirtybuffer[offs] = 0;
  234.  
  235.             sx = offs % 32;
  236.             sy = offs / 32;
  237.             col = frogger_attributesram[2 * sx + 1] & 7;
  238.             col = ((col >> 1) & 0x03) | ((col << 2) & 0x04);
  239.  
  240.             if (flipscreen)
  241.             {
  242.                 sx = 31 - sx;
  243.                 sy = 31 - sy;
  244.                 drawgfx(tmpbitmap,Machine->gfx[0],
  245.                         videoram[offs],
  246.                         col + (sx >= 16 ? 8 : 0),    /* blue background in the lower 128 lines */
  247.                         flipscreen,flipscreen,8*sx,8*sy,
  248.                         0,TRANSPARENCY_NONE,0);
  249.             }
  250.             else
  251.             {
  252.                 drawgfx(tmpbitmap,Machine->gfx[0],
  253.                         videoram[offs],
  254.                         col + (sx <= 15 ? 8 : 0),    /* blue background in the upper 128 lines */
  255.                         flipscreen,flipscreen,8*sx,8*sy,
  256.                         0,TRANSPARENCY_NONE,0);
  257.             }
  258.         }
  259.     }
  260.  
  261.  
  262.     /* copy the temporary bitmap to the screen */
  263.     {
  264.         int scroll[32];
  265.  
  266.         for (i = 0;i < 32;i++)
  267.         if (flipscreen)
  268.         {
  269.             scroll[31-i] = frogger_attributesram[2 * i];
  270.         }
  271.         else
  272.         {
  273.             scroll[i] = -frogger_attributesram[2 * i];
  274.         }
  275.  
  276.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  277.     }
  278.  
  279.  
  280.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  281.     /* order, to have the correct priorities. */
  282.     for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
  283.     {
  284.         if (spriteram[offs + 3] != 0)
  285.         {
  286.             int x,y,col;
  287.  
  288.             x = spriteram[offs + 3];
  289.             y = spriteram[offs];
  290.             col = spriteram[offs + 2] & 7;
  291.             col = ((col >> 1) & 0x03) | ((col << 2) & 0x04);
  292.  
  293.             if (flipscreen)
  294.             {
  295.                 x = 242 - x;
  296.                 y = 240 - y;
  297.                 drawgfx(bitmap,Machine->gfx[1],
  298.                         spriteram[offs + 1] & 0x3f,
  299.                         col,
  300.                         !(spriteram[offs + 1] & 0x40),!(spriteram[offs + 1] & 0x80),
  301.                         x,30*8 - y,
  302.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  303.             }
  304.             else
  305.             {
  306.                 drawgfx(bitmap,Machine->gfx[1],
  307.                         spriteram[offs + 1] & 0x3f,
  308.                         col,
  309.                         spriteram[offs + 1] & 0x40,spriteram[offs + 1] & 0x80,
  310.                         x,30*8 - y,
  311.                         &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  312.             }
  313.         }
  314.     }
  315. }
  316.